package cn.iocoder.yudao.module.crm.service.tasktype;

import cn.iocoder.yudao.module.crm.controller.admin.tasktype.vo.tasktypeapprover.TaskTypeApproverDetail;
import cn.iocoder.yudao.module.crm.controller.admin.tasktype.vo.tasktypeassignee.TaskTypeAssigneeDetail;
import cn.iocoder.yudao.module.crm.dal.dataobject.tasktype.TaskTypeApproverDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.tasktype.TaskTypeAssigneeDO;
import cn.iocoder.yudao.module.crm.dal.mysql.tasktype.TaskTypeAssigneeMapper;
import cn.iocoder.yudao.module.crm.dal.mysql.tasktype.TaskTypeMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * CRM 任务单类型处理人关联 Service 实现类
 *
 * @author 广州氪量
 */
@Service
@Validated
public class TaskTypeAssigneeServiceImpl implements TaskTypeAssigneeService {
    @Resource
    private TaskTypeAssigneeMapper taskTypeAssigneeMapper;

    @Override
    public Long getAutoIssueNum(Long id) {
        return taskTypeAssigneeMapper.countByTaskTypeId(id);
    }

    @Override
    public List<TaskTypeAssigneeDetail> getByTaskTypeId(Long id) {
        List<TaskTypeAssigneeDO> taskTypeAssigneeDOS = taskTypeAssigneeMapper.getByTaskTypeId(id);
        return taskTypeAssigneeDOS.stream()
                .map(TaskTypeAssigneeDetail::toDetail)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
    }
}